local skill = fk.CreateSkill{
  name = "tea__jingnu"
}
---@type TrigSkelSpec<TrigFunc>
local jingnu = {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player.room.current and not player.dead and player:hasSkill(self) then
      local room = player.room
      if player:getMark("tea__qiaozhu-block-phase") ~= 0 then
        room:setPlayerMark(player, "tea__qiaozhu-block-phase", 0)
        return
      end
      local current = room.current
      if not current.dead then
        local n = 0
        for _, move in ipairs(data) do
          if (move.to == player and move.toArea == Card.PlayerHand) then
            for _, info in ipairs(move.moveInfo) do
              if info.cardId then
                n = n + 1
              end
            end
          elseif move.from == player then
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) then
                n = n + 1
              end
            end
          end
        end
        if n >= current:getAttackRange() then
          event:setCostData(self, { n })
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event:getCostData(self) then
      room:addPlayerMark(room.current, "@jingnu_buff-turn", event:getCostData(self)[1])
    end
  end,
}
---@type AttackRangeSpec
local jingnu_attackrange = {
  correct_func = function (self, from, to)
    return from:getMark("@jingnu_buff-turn")
  end,
}
---@type TargetModSpec
local jingnu_targetmod = {
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("@jingnu_buff-turn") > 0 and scope == Player.HistoryPhase then
      return player:getMark("@jingnu_buff-turn")
    end
  end,
}
skill:addEffect(fk.AfterCardsMove, jingnu)
skill:addEffect("atkrange", jingnu_attackrange)
skill:addEffect("targetmod", jingnu_targetmod)
skill:addTest(function (room, me)
  local comp2 = room.players[2]
  local card = Fk:cloneCard("slash")
  local s = card.skill
  FkTest.setNextReplies(me, { "1", "1", "1", "1", "1", "1", "1", "1", }) --Yesman
  --获得牌测试
  FkTest.runInRoom(function ()
    room:handleAddLoseSkills(me, skill.name)
    me:drawCards(2)
  end)
  lu.assertEquals(me:getAttackRange(), 3)
  lu.assertEquals(s:getMaxUseTime(me, Player.HistoryPhase, card, nil), 3)
  FkTest.runInRoom(function ()
    me:drawCards(1)
    me:drawCards(3)
  end)
  lu.assertEquals(me:getAttackRange(), 6)
  lu.assertEquals(s:getMaxUseTime(me, Player.HistoryPhase, card, nil), 6)
  --失去牌测试
  FkTest.runInRoom(function ()
    room:obtainCard(comp2, me:getCardIds("h"))
  end)
  lu.assertEquals(me:getAttackRange(), 12)
  lu.assertEquals(s:getMaxUseTime(me, Player.HistoryPhase, card, nil), 12)
  FkTest.runInRoom(function ()
    GameEvent.Turn:create(TurnData:new(me, "game_rule")):exec()
  end)
  lu.assertEquals(s:getMaxUseTime(me, Player.HistoryPhase, card, nil), 1)
end)
return skill